package com.cloudspace.jindun.activity.locate;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.ListView;
import android.widget.TextView;

import com.cloudspace.jindun.R;
import com.cloudspace.jindun.activity.CustomTitleBaseActivity;
import com.cloudspace.jindun.adapter.locate.LocateAreaAdapter;
import com.cloudspace.jindun.model.LocateArea;
import com.cloudspace.jindun.model.LocateAreaResult;

import java.util.List;

/**
 * Created by zengxianhua on 17/3/4.
 */

public class LocateStatisticsActivity extends CustomTitleBaseActivity{
    private ListView listView;
    private LocateAreaAdapter adapter;
    private List<LocateArea> datas;

    private boolean departStatistics = false;

    private TextView text1;
    private TextView text3;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_locate_statistics, true);
        getTitleBar().setSimpleMode(getResources().getString(R.string.area_statistics));

        adapter = new LocateAreaAdapter();
        listView = (ListView) findViewById(R.id.lv);
        listView.setAdapter(adapter);

        text1 = (TextView) findViewById(R.id.text1);
        text3 = (TextView) findViewById(R.id.text3);

        if (getIntent() != null){
            LocateAreaResult areas = (LocateAreaResult) getIntent().getSerializableExtra("areas");

            departStatistics = TextUtils.equals(areas.msg, "0002");
            if (departStatistics){
                text1.setText(getResources().getString(R.string.department));
                text3.setVisibility(View.GONE);
            }

            if (areas != null){
                adapter.setDatas(areas.data, LocateStatisticsActivity.this);
                adapter.setType(departStatistics);
            }
        }
    }

    public static void showActivity(Context context, LocateAreaResult areas){
        Intent intent = new Intent(context, LocateStatisticsActivity.class);
        if (!(context instanceof Context)){
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        }

        intent.putExtra("areas", areas);

        context.startActivity(intent);
    }
}
